from rest_framework import serializers
from course import models
#被嵌套的小数据
class Categoryser(serializers.ModelSerializer):
    class Meta:
        model=models.Category
        fields=['cname','id']

#分类序列化器
class Categoryserializer(serializers.ModelSerializer):

    category_set=Categoryser(many=True)
    class Meta:
        model=models.Category
        fields='__all__'



class CourseSerializer(serializers.ModelSerializer):
    class Meta:
        model=models.Course
        fields='__all__'


#设置索引的序列化器
from course import search_indexes #索引的模型文件
from drf_haystack.serializers import HaystackSerializer #haystack的序列化器
class CourseIndexSerializer(HaystackSerializer):
    class Meta:
        index_classes=[search_indexes.CouseIndex] #指定索引类
        fields=["text","id","coursename","cover","price"] #指定索引字段